package com.woniuxy.main.handler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.main.pojo.Vi_user_complain;
import com.woniuxy.main.service.Vi_user_complainService;

import lombok.Data;

@Controller
@RequestMapping("/complain")
@Data
public class Vi_user_complainHandler {
	
	@Resource
	private Vi_user_complainService vi_user_complainService;
	
	//用户提交申诉
	@RequestMapping("/submitComplain")
	@ResponseBody
	public String submitComplain(int uid,String cpReason){
		String result="提交失败！";
		//检查当前用户是否已经提交过申诉
		String isExist=vi_user_complainService.isComplainExist(uid);
		if(null!=isExist||"".equals(isExist)){
			result="您已提交过申诉，请耐心等待申诉结果！";
		}else{
			//插入申诉表
			Map<String,Object> request=new HashMap<>();
			request.put("uid", uid);
			request.put("cpReason", cpReason);
			int row=vi_user_complainService.addComplain(request);
			if(row!=0){
				result="提交申诉成功！请耐心等待申诉结果！";
			}
		}
		return result;
	}
	
	//查询未处理学员申诉列表
	@RequestMapping("/showStudentComplain")
	@ResponseBody
	public Map<String,Object> showStudentComplain(Integer page){
		//System.out.println("开始运行");
		int index = (page - 1) * 8;
		Map<String,Object> result=new HashMap<String,Object>();
		List<Vi_user_complain> info=vi_user_complainService.showStudentComplain(index);
		result.put("form", info);
		//查询总页码
		int totalCount=vi_user_complainService.totalStudentComplainPage();
		int totalPage=totalCount % 8 == 0 ? totalCount / 8 : totalCount / 8 + 1;
		result.put("totalPage", totalPage);
		return result;
	}
	
	//查询未处理教练申诉列表
	@RequestMapping("/showCoachComplain")
	@ResponseBody
	public Map<String,Object> showCoachComplain(Integer page){
		//System.out.println("开始运行");
		int index = (page - 1) * 8;
		Map<String,Object> result=new HashMap<String,Object>();
		List<Vi_user_complain> info=vi_user_complainService.showCoachComplain(index);
		result.put("form", info);
		//查询总页码
		int totalCount=vi_user_complainService.totalCoachComplainPage();
		int totalPage=totalCount % 8 == 0 ? totalCount / 8 : totalCount / 8 + 1;
		result.put("totalPage", totalPage);
		return result;
	}
	
	//查询未处理会馆申诉列表
	@RequestMapping("/showGymComplain")
	@ResponseBody
	public Map<String,Object> showGymComplain(Integer page){
		//System.out.println("开始运行");
		int index = (page - 1) * 8;
		Map<String,Object> result=new HashMap<String,Object>();
		List<Vi_user_complain> info=vi_user_complainService.showGymComplain(index);
		result.put("form", info);
		//查询总页码
		int totalCount=vi_user_complainService.totalGymComplainPage();
		int totalPage=totalCount % 8 == 0 ? totalCount / 8 : totalCount / 8 + 1;
		result.put("totalPage", totalPage);
		return result;
	}

}
